<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="checkJyjg"
          :disabled="type"
          v-hasPermi="['putStorage:RhmCheck:check']"
        >
          审核
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="type"
          @click="
            check_back = true;
            title = '撤回';
          "
          v-hasPermi="['putStorage:RhmCheck:back']"
        >
          撤回
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:rhmTh:export']"
        >
          导出
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExportMx"
          v-hasPermi="['putStorage:rhmTh:exportMx']"
        >
          导出明细
        </el-button>
      </el-col>

      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="rhmThList"
      :height="tableH"
      @row-click="clickRhm"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="iCellStyle2"
    >
      <el-table-column label="#" type="index" min-width="5%" align="center" />
      <el-table-column
        label="退货单号"
        :show-overflow-tooltip="true"
        min-width="12%"
        align="center"
        prop="rhmDjbh"
      />
      <el-table-column
        label="退货日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rhmThrq"
        min-width="12%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rhmThrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="客户代码"
        :show-overflow-tooltip="true"
        min-width="10%"
        align="center"
        prop="rhmKhdm"
      >
        <template #default="scope">
          <dict-tag :options="allCustomerOptions" :value="scope.row.rhmKhdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="收货单号"
        :show-overflow-tooltip="true"
        min-width="12%"
        align="center"
        prop="rhmShdh"
      />
      <el-table-column
        label="仓库代码"
        :show-overflow-tooltip="true"
        min-width="12%"
        align="center"
        prop="rhmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.rhmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        min-width="12%"
        align="center"
        prop="rhmDesc"
      />
      <el-table-column
        label="拒收备注"
        :show-overflow-tooltip="true"
        min-width="12%"
        align="center"
        prop="rhmNgdesc"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        min-width="8%"
        align="center"
        prop="rhmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rhmJlrq"
        min-width="12%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rhmJlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="检验人员"
        :show-overflow-tooltip="true"
        min-width="8%"
        align="center"
        prop="rhmJyry"
      />
      <el-table-column
        label="检验日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rhmJyrq"
        min-width="12%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rhmJyrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        min-width="8%"
        align="center"
        prop="rhmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rhmGzrq"
        min-width="12%"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rhmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <el-table
      border
      stripe
      :height="tableHChild"
      :data="rhdDetList"
      :cell-style="iCellStyle"
    >
      >
      <el-table-column label="#" width="40" align="center" fixed="left" />
      <el-table-column label="物料代码" align="center" prop="rhdWldm" />
      <el-table-column
        label="规格描述"
        show-overflow-tooltip
        align="center"
        prop="rhdPmgg"
      />
      <el-table-column
        label="单位"
        :show-overflow-tooltip="true"
        width="60"
        align="center"
        prop="rhdDw"
      >
        <template #default="scope">
          <dict-tag :options="unitFlagOptions" :value="scope.row.rhdDw" />
        </template>
      </el-table-column>
      <el-table-column label="存放位置" align="center" prop="rhdCwdm">
        <template #default="scope">
          <dict-tag :options="allCwOptions" :value="scope.row.rhdCwdm" />
        </template>
      </el-table-column>
      <el-table-column label="申请数量" align="center" prop="rhdSqsl" />
      <el-table-column label="允收数量" align="center" prop="rhdOksl" />
      <el-table-column label="拒收数量" align="center" prop="rhdNgsl" />
      <el-table-column label="入库数量" align="center" prop="rhdRksl" />
      <el-table-column label="检验结果" align="center" prop="rhdJyjg" />
      <el-table-column label="结果描述" align="center" prop="rhdJyms" />
      <el-table-column
        label="检验人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rhdJyry"
      />
      <el-table-column
        label="检验日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rhdJyrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rhdJyrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="入库人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rhdRkry"
      />
      <el-table-column
        label="入库日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rhdRkrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rhdRkrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        width="60"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleJyResult(scope.row)"
            v-hasPermi="['putStorage:RhmCheck:testMx']"
            >检验结果</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 检验结果对话框   -->
    <el-dialog
      :title="title"
      v-model="resultOpen"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        ref="rhdForm"
        :model="rhdForm"
        label-width="88px"
        :rules="rhdRules"
      >
        <el-col :span="24">
          <el-form-item label="入库单号" prop="rhdDjbh">
            <el-input v-model="rhdForm.rhdDjbh" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="物料代码" prop="rhdWldm">
            <el-input v-model="rhdForm.rhdWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="品名规格" prop="rhdPmgg">
            <el-input v-model="rhdForm.rhdPmgg" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="检验结果" prop="rhdJyjg">
            <el-radio-group
              v-model="rhdForm.rhdJyjg"
              size="medium"
              @change="countChage"
            >
              <el-radio
                v-for="(item, index) in jyjgOptions"
                :key="index"
                :disabled="item.disabled"
                :label="item.value"
                >{{ item.label }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请数量" prop="rhdSqsl">
            <el-input v-model="rhdForm.rhdSqsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="允收数量" prop="rhdYssl">
            <el-input v-model="rhdForm.rhdYssl" @input="changValue" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="拒收数量" prop="rhdJssl">
            <el-input v-model="rhdForm.rhdJssl" @input="changValue2" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="检验描述" prop="rhdJyms">
            <el-input type="textarea" v-model="rhdForm.rhdJyms" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="jyjgSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="450px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="24">
          <el-form-item label="退货单号" prop="rhmDjbh">
            <el-input
              v-model="queryParams.rhmDjbh"
              placeholder="请输入退货单号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="建立日期">
            <el-date-picker
              v-model="daterangeRhmJlrq"
              size="small"
              :clearable="false"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="入库仓库" prop="rhmCkdm">
            <el-select
              v-model="queryParams.rhmCkdm"
              style="width: 240px"
              clearable
              filterable
              placeholder="请选择仓库"
            >
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="状态">
            <el-radio-group v-model="queryParams.rhmZtbz">
              <el-radio
                style="margin-right: 10px"
                v-for="dict in RhmZtbzOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >
                {{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 撤回对话框 -->
    <el-dialog
      :title="title"
      v-model="check_back"
      :close-on-click-modal="false"
      draggable
      width="600px"
      append-to-body
    >
      <el-form
        ref="rollbackForm"
        :model="rollbackForm"
        :rules="rollbackFormRules"
        label-width="100px"
      >
        <el-form-item label="撤回理由" prop="rhdNgdesc">
          <el-input
            v-model="rollbackForm.rhdNgdesc"
            placeholder="请输入撤回理由"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleBack">确 定</el-button>
        <el-button @click="check_back = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRhmTh,
  getRhmTh,
  delRhmTh,
  addRhmTh,
  updateRhmTh,
  exportRhmTh,
  getMx,
  addMx,
  getOrderByDjbh,
  deleteMxByCondition,
  submitMx,
  exportRhmThMx,
  testResult,
  rollback,
  check,
} from "@/api/putStorage/rhmTh";
import { getAllCustomer, getAllCustomerTwo } from "@/api/project/customer";
import { getAll, getstorageType } from "@/api/repertory/Storage";

export default {
  name: "RhmThCheck",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      //有效客户
      customerOptions: [],
      //所有客户
      allCustomerOptions: [],
      //有效仓库
      storageOptions: [],
      //所有仓库
      allStorageOptions: [],

      //撤回开单
      check_back: false,

      //审核
      // check_check:false,

      //撤回理由
      backRwmDesc: null,

      rollbackForm: {
        rhdNgdesc: "",
      },

      //所有仓位
      allCwOptions: [],
      //单位
      unitFlagOptions: [],
      //添加View
      openChildren: false,
      //明细表格数据
      childAddList: [],

      type: true,

      //检验结果模态框
      resultOpen: false,

      //底部明细数据
      rhdDetList: [],
      tableH: (document.body.clientHeight - 130) / 2,
      tableHChild: (document.body.clientHeight - 280) / 2,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      //明细总条数
      mxTotal: 0,
      // 产品退货入库开单作业表格数据
      rhmThList: [],
      //保存当前行数据
      rhmData: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 建立日期时间范围
      daterangeRhmJlrq: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],

      //保存的明细数据
      rhdDataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        rhmDjbh: null,
        rhmZtbz: "1",
        rhmJlrq: null,
        rhmTjflag: "1",
      },
      //添加View查询参数
      queryChildParams: {
        pageNum: 1,
        pageSize: 10,
        rhmCkdm: null,
        rhmDjbh: null,
        rhdWldm: null,
        rhdPmgg: null,
        rhdKh: null,
      },
      rhdForm: {},
      //请求状态
      RhmZtbzOptions: [
        {
          dictLabel: "未检验",
          dictValue: "1",
        },
        {
          dictLabel: "已检验",
          dictValue: "2",
        },
        {
          dictLabel: "全部",

          dictValue: "",
        },
      ],
      //检验结果单选组
      jyjgOptions: [
        {
          label: "允收",
          value: "OK",
        },
        {
          label: "拒收",
          value: "NG",
        },
        {
          label: "特采",
          value: "TC",
        },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rhmThrq: [
          { required: true, message: "退货日期不能为空", trigger: "blur" },
        ],
        rhmKhdm: [
          { required: true, message: "客户代码不能为空", trigger: "blur" },
        ],
        rhmCkdm: [
          { required: true, message: "仓库代码不能为空", trigger: "blur" },
        ],
        rhmTjflag: [
          { required: true, message: "仓库代码不能为空", trigger: "blur" },
        ],
        rhmZtbz: [
          {
            required: true,
            message: "状态标志(1:新增,2:审核,6:过账)不能为空",
            trigger: "blur",
          },
        ],
      },
      rhdRules: {
        rhdJyjg: [
          { required: true, message: "请选择检验结果", trigger: "blur" },
        ],
        rhdYssl: [
          { required: true, message: "请输入允收数量", trigger: "blur" },
        ],
        rhdJssl: [
          { required: true, message: "请输入拒收数量", trigger: "blur" },
        ],
      },

      rollbackFormRules: {
        rhdNgdesc: [
          { required: true, message: "请输入撤回理由", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    getAllCustomer().then((response) => {
      for (let i of response.data) {
        i.dictLabel = i.cusName;
        i.dictValue = i.cusCode;
        i.listClass = "default";
      }

      this.customerOptions = response.data;
    });

    getAllCustomerTwo().then((response) => {
      for (let i of response.data) {
        i.dictLabel = i.cusName;
        i.dictValue = i.cusCode;
        i.listClass = "default";
      }

      this.allCustomerOptions = response.data;
    });

    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getstorageType("0").then((response) => {
      this.storageOptions = response.data;
      for (let item of this.storageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;

        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });

    //单位
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
  },
  methods: {
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rhdJyjg) {
        return "color:#bb0331";
      }
    },

    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rhmZtbz === "1" && row.rhmTjflag === "1") {
        return "color:#0fac09";
      } else if (row.rhmZtbz === "6") {
        return "color:#bb0331";
      } else if (row.rhmZtbz === "2") {
        return "color:#0323af";
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.pageNum = 1
      this.getList();
      this.openSearch = false;
    },
    /** 查询产品退货入库开单作业列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRhmJlrq && "" != this.daterangeRhmJlrq) {
        this.queryParams.params["beginRhmJlrq"] = this.moment(
          this.daterangeRhmJlrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endRhmJlrq"] = this.moment(
          this.daterangeRhmJlrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listRhmTh(this.queryParams).then((response) => {
        this.rhmThList = [];
        this.rhdDetList = [];
        this.rhmThList = this.rhmThList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRhm(row);
        } else if (this.rhmThList != null && this.rhmThList.length > 0) {
          this.clickRhm(this.rhmThList[0]);
        }
      });
    },

    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 20;
        this.queryParams.pageNum++;
        listRhmTh(this.queryParams).then((response) => {
          this.rhmThList = this.rhmThList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
          if (row != null) {
            this.clickRhm(row);
          } else if (this.rhmThList != null && this.rhmThList.length > 0) {
            this.clickRhm(this.rhmThList[0]);
          }
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.openChildren = false;
      this.resultOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rhmId: null,
        rhmDjbh: null,
        rhmThrq: new Date(),
        rhmKhdm: null,
        rhmShdh: null,
        rhmCkdm: null,
        rhmDesc: null,
        rhmTjflag: null,
        rhmNgdesc: null,
        rhmZtbz: "1",
        rhmJlry: null,
        rhmJlrq: null,
        rhmJyry: null,
        rhmJyrq: null,
        rhmGzry: null,
        rhmGzrq: null,
      };

      this.resetForm("form");
    },

    resetJy() {
      this.rhdForm = {
        rhdDjbh: null,
        rhdWldm: null,
        rhdPmgg: null,
        rhdJyjg: "OK",
        rhdSqsl: null,
        rhdYssl: 0,
        rhdJssl: 0,
        rhdJyms: "无",
      };
      this.resetForm("rhdForm");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRhmJlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    jyjgSubmit() {
      this.$refs["rhdForm"].validate((valid) => {
        if (valid) {
          if (this.rhdForm.rhdJyms == null || this.rhdForm.rhdJyms === "") {
            this.rhdForm.rhdJyms = "无";
          }
          testResult(
            this.rhdForm.rhdDjbh,
            this.rhdForm.rhdWldm,
            this.rhdForm.rhdJyjg,
            this.rhdForm.rhdYssl,
            this.rhdForm.rhdJssl,
            this.rhdForm.rhdJyms
          ).then((response) => {
            this.resultOpen = false;
            this.msgSuccess("检验成功");
            this.getMxByDjbh(this.rhdForm.rhdDjbh);
          });
        }
      });
    },

    countChage(val) {
      switch (val) {
        case "OK":
          this.rhdForm.rhdYssl = this.rhdForm.rhdSqsl;
          this.rhdForm.rhdJssl = 0;
          break;
        case "TC":
          this.rhdForm.rhdYssl = this.rhdForm.rhdSqsl;
          this.rhdForm.rhdJssl = 0;
          break;
        case "NG":
          this.rhdForm.rhdJssl = this.rhdForm.rhdSqsl;
          this.rhdForm.rhdYssl = 0;
          break;
      }
    },

    handleBack() {
      this.$refs["rollbackForm"].validate((valid) => {
        if (valid) {
          rollback(this.rhmData.rhmDjbh, this.rollbackForm.rhdNgdesc).then(
            (response) => {
              this.check_back = false;
              this.msgSuccess("撤回成功");
              this.getList();
            }
          );
        }
      });
    },
    /** 效验 rhdDet 是否检验 */
    is_empty() {
      if (this.rhdDetList.length > 0) {
        let flag = true; //效验该单据至少存在一个 检验结果为 :特采、允收
        for (let i of this.rhdDetList) {
          if (i.rhdJyjg === "" || i.rhdJyjg == null) return true;
          if (i.rhdJyjg == "OK" || i.rhdJyjg == "TC") flag = false;
        }

        return flag;
      } else {
        return true;
      }
    },
    //允收、拒收 效验子项数据
    checkJyjg() {
      if (this.is_empty()) {
        this.$Modal.warning({
          title: "提示",
          content: "存在未输入检验结果或检验结果都为拒收的材料，不允许此操作",
        });
      } else {
        this.handleCheck();
      }
    },

    handleCheck() {
      this.$confirm("是否要审核?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          check(this.rhmData.rhmDjbh).then((response) => {
            this.check_check = false;
            this.msgSuccess("审核成功");
            this.getList();
          });
          // this.$message({
          //   type: 'success',
          //   message: '删除成功!'
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消审核",
          });
        });
      // check(this.rhmData.rhmDjbh).then(response => {
      //   this.check_check = false;
      //   this.msgSuccess("审核成功");
      //   this.getList();
      // })
    },

    handleSearch() {
      this.reset();
      this.title = "查询产品退货入库开单作业";
      this.openSearch = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.rhmId != null) {
            updateRhmTh(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRhmTh(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    //明细查询初始化
    searchMx() {
      this.queryChildParams.pageNum = 1;
      this.childAddList = [];
      this.realSearchMx();
      this.getMxByDjbh(this.rhmData.rhmDjbh);
    },

    //查询要添加的明细
    realSearchMx() {
      getMx(this.queryChildParams).then((response) => {
        this.childAddList = response.rows;
        this.mxTotal = response.total;
      });
    },

    changValue(value) {
      if (value > this.rhdForm.rhdSqsl || value < 0) {
        this.msgError("请输入0-" + this.rhdForm.rhdSqsl + "的数字");

        this.rhdForm.rhdYssl = this.rhdForm.rhdSqsl;
        this.rhdForm.rhdJssl = 0;
      } else {
        this.rhdForm.rhdJssl = this.rhdForm.rhdSqsl - this.rhdForm.rhdYssl;
      }
    },
    changValue2(value) {
      if (value > this.rhdForm.rhdSqsl || value < 0) {
        this.msgError("请输入0-" + this.rhdForm.rhdSqsl + "的数字");

        this.rhdForm.rhdYssl = this.rhdForm.rhdSqsl;

        this.rhdForm.rhdJssl = 0;
      } else {
        this.rhdForm.rhdYssl = this.rhdForm.rhdSqsl - this.rhdForm.rhdJssl;
      }
    },

    //打开检验模态框
    handleJyResult(row) {
      this.resetJy();

      this.rhdForm.rhdDjbh = row.rhdDjbh;
      this.rhdForm.rhdWldm = row.rhdWldm;
      this.rhdForm.rhdPmgg = row.rhdPmgg;
      this.rhdForm.rhdSqsl = row.rhdSqsl;
      this.rhdForm.rhdYssl = row.rhdOksl || row.rhdSqsl;
      this.rhdForm.rhdJssl = row.rhdNgsl || 0;
      this.resultOpen = true;
    },

    //单击查询明细
    clickRhm(row) {
      this.rhmData = row;

      this.type = !(row != null && row.rhmZtbz == "1" && row.rhmTjflag == "1");

      if (row.rhmDjbh) {
        this.getMxByDjbh(row.rhmDjbh);
      }
    },

    //根据单号查询明细
    getMxByDjbh(order) {
      getOrderByDjbh(order).then((response) => {
        this.rhdDetList = response.data;
      });
    },

    handleSubmit() {
      this.$confirm("确认提交该单据吗?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return submitMx(this.rhmData.rhmDjbh);
        })
        .then((response) => {
          this.msgSuccess("提交成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有产品退货入库开单作业数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportRhmTh(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },

    handleExportMx() {
      const queryParams = this.rhmData.rhmDjbh;
      this.$confirm("是否确认导出所有产品退货入库开单作业数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportRhmThMx(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },

    numberChage(row) {
      if (row.rhdNeedSqsl) {
        if (row.rhdNeedSqsl <= 0) {
          this.msgError("请输入大于0的数字");
          row.rhdNeedSqsl = 1;
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
